package com.shark.uh.controller;

import com.shark.uh.common.ApiResponse;
import com.shark.uh.model.dto.captcha.ImageCaptchaDTO;
import com.shark.uh.service.ImageCaptchaService;
import com.shark.uh.service.VerificationCodeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;

@RestController
public class CaptchaController {
    @Resource
    private ImageCaptchaService imageCaptchaService;

    @Resource(name = "emailVerificationCodeServiceImpl")
    private VerificationCodeService emailVerificationCodeService;

    /**
     * 获取验证码
     *
     * @return null
     */
    @GetMapping("api/verification-code/email/{email}")
    public ApiResponse<Object> getCode(@PathVariable @NotNull @Email String email) {
        emailVerificationCodeService.send(email);
        return ApiResponse.success();
    }

    @GetMapping("api/captcha/image")
    public ApiResponse<ImageCaptchaDTO> getGraphicCaptcha() {
        ImageCaptchaDTO imageCaptchaDTO = imageCaptchaService.create();
        return ApiResponse.success(imageCaptchaDTO);
    }
}
